package tianwang.biz.stat;

import java.util.List;

import tianwang.model.AticleModel;
import tianwang.model.CALexical;
import tianwang.services.collect.CollectResult;
import tianwang.services.collect.Collecter;
import tianwang.util.DictionaryUtil;
import tianwang.utils.dict.Dictionary;

/**
 * 计算第一类词汇
 * 词频最高的1000个词
 * 
 * @author tian
 *
 */
public class WordsCommonICollecter implements Collecter<CollectResult> {
	private final String name = CALexical.FIRST_1000;
	
	@Override
	public CollectResult collect(Object material) throws Exception {
		AticleModel model = (AticleModel) material;
		List<String> list = model.getEntityWords();
		Dictionary dict = DictionaryUtil.getDict(DictionaryUtil.COMMON_I_DICTIONARY);
		
		int contentWords = 0, totalWords = 0;
		for ( int i=0; i<list.size(); i++){
			String word = list.get(i);
			totalWords ++;
			if ( dict.contains(word)){
				contentWords++;
			}
		}
		
		final int lexDensity = contentWords*100/totalWords;
		return new CollectResult(){
			public Object pump(){
				return lexDensity;
			}

			@Override
			public String getName() {
				return name;
			}
		};
	}

}
